package nodes;

import java.util.Queue;
import model.Model;


/**
 * Represents a node that takes in one argument (such as not)
 * 
 * @author Andrew Patterson
 * @author Roman Zhang
 */
public abstract class AbstractUnaryNode extends AbstractNode
{
    protected AbstractNode myArgument; // Argument 1
    protected boolean operandSet; // Has this node been completely created yet?


    public AbstractUnaryNode (Model model)
    {
        super(model);
    }


    /**
     * Uses the parser stack to set the one argument
     */
    @Override
    public AbstractNode buildTree (Queue<AbstractNode> stack)
    {
        if (!operandSet)
        {
            myArgument = stack.poll().buildTree(stack);
            operandSet = true;
        }
        return this;
    }


    public AbstractNode getArgument ()
    {
        return myArgument;
    }


    @Override
    public String toString ()
    {
        return myName + " " + myArgument.toString();
    }
}
